package com.vip.mvc.netty;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.netty.handler.codec.http.HttpMethod;
import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

/**
 * http日志对象 打印路由日志
 * Created by cloudy.xie on 17/1/19.
 */
public class NettyHttpRequestParam {
    private String contentType ;
    private String host;//域名
    private String url;//除域名外的url ?之前域名之后
    private HttpMethod httpMethod;
//    private String reqParam;//地址栏参数  ?后面参数
    private Map<String,String> reqParamMap = new HashMap<>();//地址栏参数  ?后面参数
    private String reqBody;//请求结构
    private String sessionId;

    @JsonIgnore
    public boolean isValidRequest(){
        if(StringUtils.isBlank(url) || reqBody == null){
            return false;
        }
        return true;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public HttpMethod getHttpMethod() {
        return httpMethod;
    }

    public void setHttpMethod(HttpMethod httpMethod) {
        this.httpMethod = httpMethod;
    }

    public String getReqBody() {
        return reqBody;
    }

    public void setReqBody(String reqBody) {
        this.reqBody = reqBody;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

//    public String getReqParam() {
//        return reqParam;
//    }
//
    public void setReqParam(String reqParam) {
        if(StringUtils.isBlank(reqParam)){
            return;
        }
        String[] reqArr = reqParam.split("&");
        for (String reqValue :reqArr) {
            String[] reqValueArr = reqValue.split("=");
            reqParamMap.put(reqValueArr[0],reqValueArr[1]);
        }
    }

    public Map<String, String> getReqParamMap() {
        return reqParamMap;
    }

    public String getContentType() {
        return contentType;
    }

    public void setContentType(String contentType) {
        this.contentType = contentType;
    }
}


